package com.latvia.ui;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.latvia.cookingapp.R;
import com.latvia.managers.AppManager;
import com.latvia.utils.Enums;

public class MenuListViewAdapter extends BaseAdapter {
	
	private List<String> menuItems;
	private LayoutInflater inflater;
	
	public MenuListViewAdapter(Context context) {
		this.menuItems = AppManager.getInstance().getMenuItems();
		this.inflater = (LayoutInflater)context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return menuItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return menuItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (convertView == null) {
			row = inflater.inflate(R.layout.menu_row, null);
		}
		String menuTitle = menuItems.get(position);
		ImageView image = (ImageView) row.findViewById(R.id.row_icon);
		image.setImageResource(getMenuIconByPosition(position));
		TextView text = (TextView) row.findViewById(R.id.row_title);
		text.setText(menuTitle);
		return row;
	}
	
	
	private int getMenuIconByPosition(int position) {
		Enums.MenuItem item = Enums.MenuItem.getMenuItemByPosition(position);
		switch (item) {
		case ALL_CATEGORIES:
			return R.drawable.all_categories;
		case FAVOURITE:
		case FRIENDS:
		case MY_COOKING:
		case COOK_LATER:
		case ABOUT:
		case QUIT:

		default:
			return R.drawable.desert;
		}

	}
}
